//-----------------------------------------------------------------------
// <copyright file="RemoveAcl.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Andy Reeves</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>Removes an Access Control List Entry from the specified path.</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.Security
{
    using System.Globalization;
    using System;
    using System.Xml;
    using Microsoft.Build.Framework;
    using System.IO;
    using Microsoft.Sdc.Tasks.Configuration.Win32Security;

    /// <summary>
    /// Removes an Access Control List Entry from the specified path.
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Security.RemoveAcl Path="path" UserOrGroup="userOrGroup" />]]></code>
    /// <para>where:</para>
    /// <para><i>path (Required)</i></para>
    /// <para>The path to the file or folder.</para>
    /// <para><i>userOrGroup (Required)</i></para>
    /// <para>A domain user or group e.g. mydomain\user1.</para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Security.RemoveAcl
    ///             Path="c:\temp"
    ///             UserOrGroup="mydomain\user1" />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>

    public class RemoveAcl : TaskBase
    {
        private string path;
        private string userOrGroup;
        
        /// <summary>
        /// Initializes a new instance of the RemoveAcl class.
        /// </summary>
        public RemoveAcl()
        {
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            Log.LogMessageFromResources("Acl.RemovePermissions", userOrGroup, path);
            Microsoft.Sdc.Tasks.Configuration.Win32Security.Acl.Remove(userOrGroup, path);
        }

        /// <summary>
        /// The path to the file or folder.
        /// </summary>
        /// <value>The path to the file or folder.</value>
        [Required]
        public string Path
        {
            get
            {
                return (path == null ? String.Empty : path);
            }
            set
            {
                path = value;
            }
        }

        /// <summary>
        /// A domain user or group.
        /// </summary>
        /// <value>A domain user or group e.g. mydomain\user1.</value>
        [Required]
        public string UserOrGroup
        {
            get
            {
                return (userOrGroup == null ? String.Empty : userOrGroup);
            }
            set
            {
                userOrGroup = value;
            }
        }
    }
}

